<template>
  <view class="container">
    <!-- 数据列表 -->
    <view v-for="item in dataList" :key="item.id" class="data-item">
        <p>ID号: {{ item.id }}</p>
		<p>平台: {{ item.platformName }}</p>
    </view>

    <!-- 分页器 -->
    <view class="pagination">
      <button 
        class="page-btn" 
        :disabled="currentPage === 1" 
        @click="changePage(currentPage - 1)"
      >
        上一页
      </button>

      <text class="page-info">第 {{ currentPage }} 页 / 共 {{ totalPages }} 页</text>

      <button 
        class="page-btn" 
        :disabled="currentPage === totalPages" 
        @click="changePage(currentPage + 1)"
      >
        下一页
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      dataList: [], // 当前页的数据
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页条数
      totalPages: 0, // 总页数
	  id:1,
	  storeId:1,
	  merchantId:1,
	  
    };
  },
  onLoad(options){
	  this.storeId=options.data.storeId
  },
  mounted() {
    this.fetchData(); // 页面加载时获取数据
  },
  methods: {
    // 获取数据
	async fetchData() {
	try {
    const response = await uni.request({
      url: 'http://zhaoyang.nat300.top/review/findAll', // 替换为你的接口地址
      method: 'POST',
      data: {
        storeId: this.storeId,
        page: this.currentPage,
        size: this.pageSize,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log('checkinfoPOST 请求成功:', res);
        // 处理请求状态
        if (res.statusCode === 200) {
          const resData = res.data;
          this.dataList = resData.data; // 当前页数据
          this.totalPages = Math.ceil(resData.total / this.pageSize); // 计算总页数
        }
      },
      fail: (error) => {
        console.error('POST 请求失败:', error);
        uni.showToast({
          title: '请求失败，请重试',
          icon: 'none'
        });
      }
    });
  } catch (error) {
    console.error('请求异常:', error);
    uni.showToast({
      title: '请求异常，请重试',
      icon: 'none'
    });
  }
  },
// 切换页码
changePage(page) {
  if (page > 0 && page <= this.totalPages) {
    this.currentPage = page;
    this.fetchData();
  }
},
}
}
</script>

<style scoped>
.container {
  padding: 20px;
}
.data-item {
  padding: 10px;
  border-bottom: 1px solid #ddd;
}
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
}
.page-btn {
  padding: 10px 15px;
  background-color: #007aff;
  color: white;
  border: none;
  border-radius: 5px;
  margin: 0 10px;
  cursor: pointer;
}
.page-btn:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}
.page-info {
  margin: 0 10px;
  font-size: 16px;
}
</style>
